
import WxValidate from '../../../utils/WxValidate.js'


Page({

  /**
   * 页面的初始数据
   */
  data: {
    
      userName: '',
      phone: '',
      address: '',
      clothNumber: '',
      date: '2019-06-05',
      demand: '',
   

  },
// ....................................................
  nameDateChange: function(e){
    // console.log(e.detail.value)
    this.setData({
      userName:e.detail.value

    })
   

  },
  // ....................................................
  phoneDateChang: function(e){
    this.setData({
      phone:e.detail.value
    })
  },

  addressDateChang:function(e){
    this.setData({
      address:e.detail.value
    })
  },
  // ....................................................
  numberDateChang:function(e){
    this.setData({
      clothNumber:e.detail.value
    })
  },
  // ....................................................
// 时间pick联动
  bindDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },

// ....................................................
  demandDate: function(e){
    // console.log(e.detail.value)
    this.setData({
      demand:e.detail.value
    })
    
  },
// ....................................................
  

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    
    this.initValidate()//验证规则函数
  },

  showModal(error) {
    wx.showModal({
      content: error.msg,
      showCancel: false,
    })
  },
  initValidate() {
    const rules = {
      name: {
        required: true,
        minlength: 2,
        maxlength:4,
      },
      phone: {
        required: true,
        tel: true
      },
      clothNumber:{
        required: true,
      },
      address:{
        required: true,
      }
    }
    const messages = {
      name: {
        required: '请填写姓名',
        minlength: '请输入2~4个汉字'
      },
      phone: {
        required: '请填写手机号',
        tel: '请填写正确的手机号'
      },
      clothNumber:{
        required:'请填写衣物数量',
      }
    }
    this.WxValidate = new WxValidate(rules, messages)
  },


  bindsubmit:function(e){
    

      // console.log('form发生了submit事件，携带的数据为：', e.detail.value)
      const params = e.detail.value
    // console.log(params)
      // 校验表单
      if (!this.WxValidate.checkForm(params)) {
        const error = this.WxValidate.errorList[0]
        this.showModal(error)
        return false
      }

   
      // this.showModal({
      //   msg: '信息填写成功',
        
      // })
    wx.navigateTo({
      url: `confirmWashing?userName=${params.name}&phone=${params.phone}&address=${params.address}&clothNumber=${params.clothNumber}&date=${params.pick}&demand=${params.demand}`
      // url:"../confirmWashing/confirmWashing?userName=廖宝锋&phone=15629120083"

    })



    wx.showToast({
      title: '信息填写成功',
      icon: 'success',
      duration: 3000
    })


  },

 


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})